package com.oncecloud.devops.service.sample.bean;

import com.alibaba.druid.util.StringUtils;
import com.oncecloud.devops.service.sample.common.GitLab;

public class RequestCommand {
	/**
	 * 查询所有project
	 * @param gitLab
	 * @return
	 */
	public static String getProjectsCommand(GitLab gitLab){
		String command = gitLab.getHttp_protocol()+"://"+gitLab.getGitLab_url()+":"+gitLab.getGitLab_port()+"/api/"+gitLab.getGitLab_api_version()+"/projects";
		return command;
	}
	/**
	 * 查询所有project
	 * @param gitLab
	 * @return
	 */
	public static String getSingleProjectCommand(GitLab gitLab){
		String command = gitLab.getHttp_protocol()+"://"+gitLab.getGitLab_url()+":"+gitLab.getGitLab_port()+"/api/"+gitLab.getGitLab_api_version()+"/projects/"+gitLab.getProject_id();
		return command;
	}
	/**
	 * 获取分支
	 * @param gitLab
	 * @return
	 */
	public static String getProjectBranchsCommand(GitLab gitLab){
		String command = gitLab.getHttp_protocol()+"://"+gitLab.getGitLab_url()+":"+gitLab.getGitLab_port()+"/api/"+gitLab.getGitLab_api_version()
		+"/projects/"+gitLab.getProject_id()+"/repository/branches";
		return command;
	}
	/**
	 * 获取分支
	 * @param gitLab
	 * @return
	 */
	public static String getProjectSingleBranchCommand(GitLab gitLab){
		String command = gitLab.getHttp_protocol()+"://"+gitLab.getGitLab_url()+":"+gitLab.getGitLab_port()+"/api/"+gitLab.getGitLab_api_version()
		+"/projects/"+gitLab.getProject_id()+"/repository/branches/"+gitLab.getProject_branch();
		return command;
	}
	/**
	 * 获取项目设置的钩子信息
	 * @param gitLab
	 * @return
	 */
	public static String getProjecthooksCommand(GitLab gitLab){
		String command = gitLab.getHttp_protocol()+"://"+gitLab.getGitLab_url()+":"+gitLab.getGitLab_port()+"/api/"+gitLab.getGitLab_api_version()
		+"/projects/"+gitLab.getProject_id()+"/hooks";
		return command;
	}
	/**
	 * 源码clone到指定目录
	 * @param dir
	 * @param branch
	 * @return
	 */
	public static String gitCloneCommand(String gitAddress,String dir,String branch){
		String command="sudo git clone "+gitAddress+" "+dir;
		if(!StringUtils.isEmpty(branch)){
			command += " -b "+branch;
		}
		return command;
	}
	/**
	 * 代码质量分析
	 * @param dir
	 * @return
	 */
	public static String sonarAnalysisCommand(String dir){
		String command = "cd "+dir+";";
		command += "mvn sonar:sonar;";
		return command;
	}
	/**
	 * 单元测试
	 * @param dir
	 * @return
	 */
	public static String unitTestCommand(String dir){
		String command = "cd "+dir+";";
		command += "mvn test;";
		return command;
	}
	/**
	 * 跳过测试，直接打包
	 * @param dir
	 * @return
	 */
	public static String mvnPackageCommand(String dir){
		String command = "cd "+dir+";";
		command += " mvn clean package -Dmaven.test.skip=true;";
		return command;
	}
	
}
